#include <time.h>
#include <stdio.h>

int seq_search(int key, int A[], int n) {
    for (int i = n - 1; i >= 0; --i) {
        if(key == A[i])
            return 1;
    }

    return 0;
}

int seq_search_with_watcher(int key, int A[], int n) {
    int i;
    for (i = n - 1; A[i] != key; --i)
        ;

    return i;
}

int main()
{
    int A[]  =    {1, 2, 4, 10, 5, 7, 3, 1, 18};
    int B[] = {1, 2, 4, 10, 5, 7, 3, 1, 18};
    int n = sizeof(A) / sizeof(int);

    clock_t start,end;
    start = clock();

    for (int k = 0; k < 1000000; ++k) {
        seq_search(7, A, n);
    }

    end = clock();
    printf("time1 = %f\n",(double)(end-start)/CLOCKS_PER_SEC);

    start = clock();

    for (int k = 0; k < 1000000; ++k) {
        seq_search_with_watcher(7, B, n);
    }

    end = clock();
    printf("time2 = %f\n",(double)(end-start)/CLOCKS_PER_SEC);

}